package com.yzd.xander.dao.impl;

import com.yzd.xander.dao.GroupDataDao;
import com.yzd.xander.entity.Group;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by YE on 2018-06-05.
 */
@Repository("groupDataDao")
public class GroupDataDaoImpl extends HibernateDaoSupport implements GroupDataDao {

    @Override
    public List<Group> getByQQ(int QQNum) {
        Session session = getHibernateTemplate().getSessionFactory().openSession();
        List<Group> list=session.createSQLQuery("{Call SearchByQQ(" + QQNum + ")}").addEntity(Group.class).list();
        return list.size()>0?list:null;
    }

    @Override
    public List<Group> getByQun(int Qun) {
        String proc = "{Call SearchQunMember(?)}";
        Session session = getHibernateTemplate().getSessionFactory().openSession();
        List<Group> list=session.createSQLQuery("{Call SearchQunMember(" + Qun + ")}").addEntity(Group.class).list();
        return list.size()>0?list:null;
    }

    @Autowired
    public void setMySessionFactory(SessionFactory sessionFactory) {
        super.setSessionFactory(sessionFactory);
    }
}
